package com.magicsoft.share.ui.main;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

import com.magicsoft.share.R;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.utils.SPUtils;

public class SplashActivity extends AppCompatActivity {

    private boolean isLogin=true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //设置全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);

        init();
    }

    private void init() {
        final Intent intent = new Intent();
        if (isLogin()) {
            intent.setClass(this, MainActivity.class);
        } else {
            intent.setClass(this, LoginActivity.class);
        }
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                startActivity(intent);
                finish();
            }
        }, 2000);
    }

    public boolean isLogin() {
        long id = SPUtils.getInstance().getLong(SPKey.ID);
        if (id != -1) {
            isLogin = true;

        }
        return isLogin;
    }
}
